package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.MarketOrder;
import com.cskaoyan.bean.leihao.bo.OrderReplyBo;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.param.CommonData;
import com.cskaoyan.bean.wubang.bo.OrderListBO;
import com.cskaoyan.bean.wubang.bo.OrderRefund;
import com.cskaoyan.bean.wubang.bo.OrderShipBO;
import com.cskaoyan.bean.wubang.vo.OrderChannelVO;
import com.cskaoyan.bean.wubang.vo.OrderDetailVO;
import com.cskaoyan.service.OrderService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * @auther: wubang
 * @description:
 * @date: 2022-06-28 09:14
 */
@RestController
@RequestMapping("admin/order")
public class OrderController {
    @Autowired
    OrderService orderService;
    @RequiresPermissions(value = {"*","admin:order:list"},logical = Logical.OR)
    @RequestMapping("list")
    public BaseRespVo list(BaseParam baseParam, OrderListBO orderListBO) {
        CommonData<MarketOrder> orders = orderService.selectOrderList(baseParam,orderListBO);
        return BaseRespVo.ok(orders);
    }
    @RequiresPermissions(value = {"*","admin:order:detail"},logical = Logical.OR)
    @RequestMapping("detail")
    public BaseRespVo detail(Integer id) {
        OrderDetailVO order = orderService.selectOrder(id);
        return BaseRespVo.ok(order);
    }
    @RequiresPermissions(value = {"*","admin:order:ship"},logical = Logical.OR)
    @RequestMapping("ship")
    public BaseRespVo ship(@RequestBody OrderShipBO orderShipBO) {
        orderService.updateShip(orderShipBO);
        return BaseRespVo.ok();
    }


    @RequiresPermissions(value = {"*","admin:order:refund"},logical = Logical.OR)
    @RequestMapping("refund")
    public BaseRespVo refund(@RequestBody OrderRefund orderRefund) {
        orderService.updaterefund(orderRefund);
        return BaseRespVo.ok();
    }

    /**商品评论回复
     * @Auther leihao
     * @Date 16:35 2022/6/30
     * @Param
     * @Return
     **/
    @RequiresPermissions(value = {"*","admin:order:reply"},logical = Logical.OR)
    @RequestMapping("reply")
    public BaseRespVo reply(@RequestBody OrderReplyBo replyBo){
        Boolean toReply = orderService.reply(replyBo);
        if(toReply){
            return BaseRespVo.ok();
        }
        return BaseRespVo.replyError();
    }


    @RequiresPermissions(value = {"*","admin:order:channel"},logical = Logical.OR)
    @RequestMapping("channel")
    public BaseRespVo channel(){
        ArrayList<OrderChannelVO> orderChannelVOS = new ArrayList<>();
        orderChannelVOS.add(new OrderChannelVO("ZTO","中通快递"));
        orderChannelVOS.add(new OrderChannelVO("YTO","圆通速递"));
        orderChannelVOS.add(new OrderChannelVO("YD","韵达速递"));
        orderChannelVOS.add(new OrderChannelVO("YZPY","邮政快递包裹"));
        orderChannelVOS.add(new OrderChannelVO("EMS","EMS"));
        orderChannelVOS.add(new OrderChannelVO("DBL","德邦快递"));
        orderChannelVOS.add(new OrderChannelVO("FAST","快捷快递"));
        orderChannelVOS.add(new OrderChannelVO("ZJS","宅急送"));
        orderChannelVOS.add(new OrderChannelVO("TNT","TNT快递"));
        orderChannelVOS.add(new OrderChannelVO("UPS","UPS"));
        orderChannelVOS.add(new OrderChannelVO("DHL","DHL"));
        orderChannelVOS.add(new OrderChannelVO("FEDEX","FEDEX联邦(国内件)"));
        orderChannelVOS.add(new OrderChannelVO("FEDEX_GJ","FEDEX联邦(国际件)"));
        return BaseRespVo.ok(orderChannelVOS);
    }
}
